<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>牛马新闻中心</title>
    <link rel="stylesheet" type="text/css" href="./CSS/Index.css" />
    <link rel="stylesheet" type="text/css" href="./CSS/Header.css"/>
    <link rel="stylesheet" type="text/css" href="./CSS/LRCSS.css" />
    <script type="text/javascript" src="./JS/CheckLogin.js" defer="defer"></script>
	<!--检查登录态-->
	<script type="text/javascript" src="./JS/LGRE.js" defer="defer"></script>
	
</head>
<body>
	<div id="MC"></div>
    <div id="Login">
	    <span id="Lx" style="font-size: 34px">x</span>
	    <img src="./IMGS/boji.jpg" alt="Avatar" width="30%" style="border-radius: 50%"><br/><br/>
	    <span>用户名</span><br/>
	    <input type="text" id="Uname" name="Uname" placeholder="请输入用户名"/><br/>
	    <span>密码</span><br/>
	    <input type="password" id="Upassword" name="Upass" placeholder="请输入密码"/>
	    <input type="button" id="Loginsub" value="登录"/>
	    <input type="button" id="gtre" onclick="GBRegister()" value="去注册"/><br/>
	    <span id="LGMSG" style="color: red"></span>
    </div>
    <script type="text/javascript">
		document.getElementById("Loginsub1").onclick=function () {
		    var name = document.getElementById("Uname").value;
		    var pass = document.getElementById("Upassword").value;
		    var request1 = ajaxFunction();
		    // 2 发送请求 参数1:选择发送方式  参数2:发送地址(这里发送给一个Servlet)  参数3:是否异步传输(一般为true)
		    request1.open("POST", "./LoginServlet", false);
		    // 3 获取请求响应数据 注册监听  状态如果发生变化 会执行等号右边的函数
		    request1.onreadystatechange = function() {
		        //前半段表示 已经能够正常处理。  再判断状态码是否是200
		        if (request1.readyState == 4 && request1.status == 200) {
		        	var test = eval("("+request.responseText+")");
		        	var address = test[0].address;
		        	if(address=="Login"){
		        		window.location.href='./PAGES/Login.jsp';
		        	}
		        	if(address=="index"){
		        		window.location.href='index.jsp';
		        	}
		        }
		    }
		    request1.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		    request1.send("Uname="+name+"&Upassword="+pass);
		}
	</script>
    <div id="Register">
	    <span id="Rx" style="font-size: 34px">x</span>
	    <img src="./IMGS/cat.jpeg" alt="Avatar" width="30%" style="border-radius: 50%"><br/><br/>
	    <span>&nbsp;&nbsp;用户名：</span><br/>
	    <input type="text" id="RUname" name="Uname" placeholder="请输入用户名(小于10位)"/><br/>
	    <span>&nbsp;&nbsp;密码：</span><br/>
	    <input type="password" id="RUpassword" name="Upass" placeholder="请输入密码（6-16位）"/><br/>
	    <span>&nbsp;&nbsp;确认密码：</span><br/>
	    <input type="password" id="QRUpassword" name="Upass" placeholder="请输入密码"/><br/>
	    <span>&nbsp;&nbsp;邮箱：</span><br/>
	    <input type="text" id="RUmail" name="Umail" placeholder="请输入邮箱"/><br/>
	    <span>&nbsp;&nbsp;验证码：</span><br/>
	    <input type="text" id="YZ" name="Umail" placeholder="请输入验证码" style="width: 50%"/>
	    <input type="button" id="code" onclick="cc()" style="width: 40%;" title='点击更换验证码'/><br/>
	    <input type="button" id="Registersub" value="注册"/>
    </div>
<div class="header">
    <div class="header_1">
        <ul id="header_1_1">
            <li onclick="window.location='index.jsp'">首页</li>
            <li onclick="window.location='./PAGES/News_Type.jsp'">新闻分类</li>
            <li onclick="window.location='./PAGES/Allnews.jsp'">全部新闻</li>
        </ul>
        <ul id="header_1_2">
            <li class="unLogin" onclick="CBRegister()"><span>注册</span></li>
            <li class="unLogin" onclick="CBLogin()"><span>登录</span></li>
            <li class="Logining" style="display: none" onclick="LGExit()"><span>退出</span></li>
            <li class="AdminLogin" style="display: none"><span onclick="window.location='./ADMIN/Admin.jsp'">后台管理</span></li>
        </ul>
    </div>
    <div class="header_2">
    <span style="float: left;font-family: 楷体" onclick="window.location='index.jsp'"><img src="./IMGS/牛.png" height="40px" alt=""/>牛马新闻中心<img src="./IMGS/马.png" height="40px" alt=""/></span>
        <div id="H-right">
            <form action="./PAGES/Search_result.jsp" method="get">
                <button style="float: right" type="submit" id="sub">搜索</button>
                <input style="float: right" id="check" type="text" placeholder="请输入您要搜索的内容..." value="">
                <script>
                    document.getElementById("sub").onclick=function () {
                        var check = document.getElementById("check").value;
                        localStorage.setItem("check",check);
                    }
                </script>
            </form>
        </div>
    </div>
</div>
<div class="re" style="margin-top:25px;">
    <ul>
        <li><img src="IMGS/03.jpeg" width="100%" alt="图片"></li>
        <li><img src="IMGS/04.png" width="100%" alt="图片"></li>
        <li><img src="IMGS/05.png" width="100%" alt="图片"></li>
        <li><img src="IMGS/06.png" width="100%" alt="图片"></li>
    </ul>
</div>
<div class="Recent_news">
    <span>近期新闻</span><span style="float: right;cursor: pointer" onclick="window.location='./PAGES/Allnews.jsp'">更多...</span><br/>
    <div class="Recent_news_news" id="Recent_news_news">
        <span class="News_title" onclick="GO(this)">新闻标题</span><span class="Recent_news_right">2021-11-31 12:10:30</span><br/>
        <span class="News_title" onclick="GO(this)">新闻标题</span><span class="Recent_news_right">2021-11-31 12:10:30</span><br/>
        <span class="News_title" onclick="GO(this)">新闻标题</span><span class="Recent_news_right">2021-11-31 12:10:30</span><br/>
        <span class="News_title" onclick="GO(this)">新闻标题</span><span class="Recent_news_right">2021-11-31 12:10:30</span><br/>
        <span class="News_title" onclick="GO(this)">新闻标题</span><span class="Recent_news_right">2021-11-31 12:10:30</span><br/>
    </div>
</div>
</body>
<script type="text/javascript">
    function GYS(){
    	var NTitle = document.getElementsByClassName('News_title');
        for(var i=0;i<5;i++){
            NTitle[i].onmousedown=function () {
                this.style.color='red';
            }
            NTitle[i].onmouseup=function () {
                this.style.color='blue';
            }
        }
    }

</script>
<!--更改字体颜色-->
<script type="text/javascript">
    var box=this.document.getElementsByClassName("re")[0];
    var lik=box.getElementsByTagName("li");
    function fun(i,j) {
        lik[i].style.opacity=1;
        lik[j].style.opacity=0;
    }
    fun(0,1);
    var i =0;
    function auto() {
        if(++i>=4) {
            i=0;
            fun(0,3);
        } else fun(i,i-1);
    }
    var timer=this.setInterval(auto,5000);
    box.onmouseover = function ()
    {
        clearInterval(timer);
    }
    box.onmouseout=function()
    {
        timer = setInterval(auto, 5000);
    }
</script>
<!--轮播图-->
<script type="text/javascript">
    function ajaxFunction() {
        var xmlHttp;
        try { // Firefox, Opera 8.0+, Safari
            xmlHttp = new XMLHttpRequest();
        } catch (e) {
            try {// Internet Explorer
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                }
            }
        }
        return xmlHttp;
    }
    // 创建AJAX
    function Onloading() {
        var sql="Select * from newsdetail  INNER JOIN types on newsdetail.type = types.tid  order by time desc ";
        var request = ajaxFunction();
        // 2 发送请求 参数1:选择发送方式  参数2:发送地址(这里发送给一个Servlet)  参数3:是否异步传输(一般为true)
        request.open("POST", "GetMessagesServlet", true);			//全部新闻
        // 3 获取请求响应数据 注册监听  状态如果发生变化 会执行等号右边的函数
        request.onreadystatechange = function() {
            //前半段表示 已经能够正常处理。  再判断状态码是否是200
            if (request.readyState == 4 && request.status == 200) {
                //弹出响应的信息
                var test = eval("("+request.responseText+")");
                var news ="";
                for(var i=0;i<5;i++){
                    news+='<span class="News_title" onclick="GO(this)">'+test[i].title+'</span><span class="Recent_news_right">'+test[i].time+'</span><br/>';
                }
                document.getElementById("Recent_news_news").innerHTML=news;
                GYS();
            }
        }
        request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        request.send("sql="+sql);
    }
    Onloading();
</script>
<!--获取数据-->
<script type="text/javascript">
    function GO(nT) {
        window.localStorage.setItem("title",nT.innerHTML);
        window.location="./PAGES/News_detail.jsp";
    }
</script>
<!--新闻标题点击事件-->
</html>